<script setup>
import { repGetReportTeacherService, repDelReportService, reqGerGradeReService } from '@/api/report'
import { ref, computed } from 'vue'
import { Delete, Edit, Search } from '@element-plus/icons-vue'

import teacherDrawerVue from '@/components/teacherDrawer.vue'
// 导入并注册读取本地用户信息
import { useUserStore } from '@/stores'
const userStore = useUserStore()

// 实验报告信息
const reportInfo = ref()
// 获取实验报告
const getReport = async () => {
    const { data } = await repGetReportTeacherService(userStore.userInfo.job)
    console.log(data);
    reportInfo.value = data.data
    changeReportInfo()
}

// 审批和待审批的实验报告
const comReportInfo = ref([])
const failReportInfo = ref([])

// 计算
const changeReportInfo = () => {
    comReportInfo.value = []
    failReportInfo.value = []
    reportInfo.value.forEach((item, index) => {
        if (item.mark) {
            comReportInfo.value.push(item)
        } else {
            failReportInfo.value.push(item)
        }
    })
}

// 接收子组件--每页展示多少条数据
// 每页条数
const pageSize = ref()
// 当前页数
const currentPage = ref()

const pageSizes = (obj) => {
    pageSize.value = obj.pageSize.value
    currentPage.value = obj.currentPage.value
}

// 接收子组件--每页展示多少条数据
// 每页条数
const pageSize2 = ref()
// 当前页数
const currentPage2 = ref()

const pageSizes2 = (obj) => {
    pageSize2.value = obj.pageSize.value
    currentPage2.value = obj.currentPage.value
}

// 删除按钮
const delBtn = (id) => {
    ElMessageBox.confirm(
        '你确定要删除这条实验报告吗?',
        '警告',
        {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
        }
    )
        .then(async () => {
            await repDelReportService(id)
            getReport()
            ElMessage({
                type: 'success',
                message: '删除成功！',
            })
        })
        .catch(() => {
            ElMessage({
                type: 'info',
                message: '取消删除',
            })
        })
}

// 弹框组件
const teacherDrawer = ref()

// 这是要向子组价传的
const rowData = ref({ a: '12' })

// 查看表中的数据
const openDrawer = (row) => {
    rowData.value = row
    teacherDrawer.value.changeDrawerState()
}

const newFormValue = (flag) => {
    if (flag) {
        getReport()
    }
}

const formDate = ref([])

// 获取成绩构成
const getGradeR = async () => {
    const { data } = await reqGerGradeReService()
    console.log(data);
    formDate.value = data.data
}

getGradeR()
getReport()
</script>

<template>
    <div class="notice-te">
        <div class="left">
            <el-tabs type="border-card" style="width: 50vw;">
                <el-tab-pane label="待审批">
                    <el-table :data="failReportInfo.slice((currentPage - 1) * pageSize, currentPage * pageSize)"
                        height="500" style="width: 100%;" class="table-one">
                        <el-table-column label="序号" type="index" index="1" width="80"></el-table-column>
                        <el-table-column label="学号" prop="uid"></el-table-column>
                        <el-table-column label="实验名称" prop="title"></el-table-column>
                        <el-table-column label="提交时间" prop="date"></el-table-column>
                        <el-table-column label="操作">
                            <template #default="scope">
                                <el-button plain circle type="primary" :icon="Search"
                                    @click="openDrawer(scope.row)"></el-button>
                                <el-button plain circle type="danger" :icon="Delete"
                                    @click="delBtn(scope.row.id)"></el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination">
                        <pagination :tableDataTotal="failReportInfo.length" @page-sizes="pageSizes"
                            :pageArray="pageArray"></pagination>
                    </div>
                </el-tab-pane>
                <el-tab-pane label="已审批">
                    <el-table :data="comReportInfo.slice((currentPage2 - 1) * pageSize2, currentPage2 * pageSize2)"
                        height="500" style="width: 100%;" class="table-two">
                        <el-table-column label="序号" type="index" index="1" width="80"></el-table-column>
                        <el-table-column label="学号" prop="uid"></el-table-column>
                        <el-table-column label="实验名称" prop="title"></el-table-column>
                        <el-table-column label="提交时间" prop="date"></el-table-column>
                        <el-table-column label="操作">
                            <template #default="scope">
                                <el-button plain circle type="primary" :icon="Edit"
                                    @click="openDrawer(scope.row)"></el-button>
                                <el-button plain circle type="danger" :icon="Delete"
                                    @click="delBtn(scope.row.id)"></el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination">
                        <pagination :tableDataTotal="comReportInfo.length" @page-sizes="pageSizes2"
                            :pageArray="pageArray">
                        </pagination>
                    </div>
                </el-tab-pane>
            </el-tabs>
        </div>

        <div class="right">
            <el-form :label-position="right" label-width="auto" style="margin: 70px 0 0 80px;">
                <!-- <el-form-item label="部分" class-name="bufen">
                    <span>权重</span>
                </el-form-item> -->
                <div class="tou-box">
                    <div>部分</div>
                    <div>权重</div>
                </div>
                <el-form-item v-for="item in formDate" :label="item.title">
                    <el-input v-model="item.quanz" disabled></el-input>
                </el-form-item>
            </el-form>
        </div>

        <!-- 弹框组件 -->
        <teacherDrawerVue @newFormValue="newFormValue" ref="teacherDrawer" :rowData="rowData"></teacherDrawerVue>
    </div>
</template>

<style scoped lang="scss">
.notice-te {
    display: flex;
}

.tou-box {
    display: flex;
    justify-content: space-between;
    padding: 0 100px 20px 30px;
    font-weight: bold;
    color: #909399;
}

.pagination {
    position: fixed;
    bottom: 5px;
    background-color: #fff;
    z-index: 999;
}
::v-deep .el-table__row .el-table__cell .cell {
    white-space: nowrap;
}
</style>